

#ifndef __QLOGGER_H__
#define __QLOGGER_H__


#include <QtCore/QtCore>
#include "QtExt.h"

enum QLogLevel
{
    Q_LOG_LVL_DEBUG = QtDebugMsg,
    Q_LOG_LVL_WARNING = QtWarningMsg,
    Q_LOG_LVL_CRITICAL = QtCriticalMsg,
    Q_LOG_LVL_FATAL = QtFatalMsg,
    Q_LOG_LVL_MAX
};


class QTEXT_DLL QLogger
{
private:
	QLogger();
	virtual ~QLogger();
	
public:
	static QLogger &instance();
    
    bool init(const QString &fileName, bool forceOutput = false, bool async = false);
    
    void write(QLogLevel level, const char *file, int line, const QString &msg);
    void write(QLogLevel level, const char *file, int line, const char *fmt, ...);
	
private:
    void output(QtMsgType type, const char *file, int line, const QString &msg);
    
	static QLogger msInstance;
    
    QFile   *mFile;
    QMutex  mMutex;
    
    bool    mForceOutput;
    bool    mAsyncMode;
};


#define Q_LOG(level, msg)               QLogger::instance().write(level, __FILE__, __LINE__, msg)
#define Q_LOG_FORMAT(level, fmt, ...)   QLogger::instance().write(level, __FILE__, __LINE__, fmt, ##__VA_ARGS__)


#endif	/*__QLOGGER_H__*/
